package kieper.rpcgen;

import gnu.getopt.Getopt;
import org.apache.log4j.Logger;
import xsd.kieper.MessageSet;

public class RpcGenMain {

    private static final Logger logger = Logger.getLogger(RpcGenMain.class);

    public static void main(String[] args) {

        // The path of the file to be parsed
        String inputFileName = null;

        // The directory to place the generated stubs in
        String outputDirName = null;

        // The namespace to generate c++ files in
        String cppNamespace = "kieper";

        Getopt go = new Getopt("rpcgen", args, "d:f:n:");
        
        int c;
        while ((c = go.getopt()) != -1) {
            switch (c) {
                case 'd':
                    outputDirName = go.getOptarg();
                    break;
                case 'f':
                    inputFileName = go.getOptarg();
                    break;
                case 'n':
                    if (outputDirName == null) {
                        usage();
                    }
                    break;
                case '?':
                    usage();
                    break;
                default:
                    usage();
            }
        }

        logger.info("Output directory name: " + outputDirName);
        logger.info("Input file name: " + inputFileName);
        logger.info("C++ namespace: " + cppNamespace);

        try {
            MessageSet ms = XmlParser.parse(inputFileName);
        } catch (ParseException e) {
            System.err.println(e.getMessage());
            if (e.getValidationErrors() != null) {
                for (ValidationError error : e.getValidationErrors()) {
                    System.err.println("\t" + error.getMessage());
                }
            }
        }
    }

    public static void usage() {
        System.err.println("Usage:");
        System.exit(-1);
    }
}
